%Beta Robust Trim estimation
function [beta]  = BetaRobustTrim(rStock,rIndex)

    percent = 1;

    %setting the values smaller than the alpha quantile to that of the alpha quantile 
    rIndex(find(rIndex <= (prctile(rIndex, (percent / 2)))))=(prctile(rIndex, (percent / 2)));
    rStock(find(rStock <= (prctile(rStock, (percent / 2)))))=(prctile(rStock, (percent / 2)));
    %setting the values larger than the alpha quantile to those of that of the alpha quantile 
    rIndex(find(rIndex >= (prctile(rIndex, (100-percent/2)))))=(prctile(rIndex, (100-percent/2)));
    rStock(find(rStock >= (prctile(rStock, (100-percent/2)))))=(prctile(rStock, (100-percent/2)));

    beta = robustfit(rIndex,rStock,'ols');
    beta = beta(2,:);
end